package jee.boot.module.authority.rest;

import jee.boot.common.basic.CrudController;
import jee.boot.common.basic.result.ResponseMessage;
import jee.boot.common.basic.result.Result;
import jee.boot.entity.auth.Account;
import jee.boot.common.standard.AccountHandler;
import jee.boot.module.authority.service.UserService;
import jee.boot.entity.auth.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户
 */
@RestController
@RequestMapping(value = "/user")
public class UserController extends CrudController<UserService, User> {
    @Autowired
    private AccountHandler accountHandler;
    /**
     * 查询用户的所有权限配置
     *
     * @param entity
     * @return
     */
    @PostMapping("/authorization")
    public ResponseMessage<User> authorization(@RequestBody Account entity) {
        User user=new User();
        user.setAccount(entity);
        User data = service.authorization(user);
        return Result.success(data);
    }
    /**
     * 查询当前session用户的所有权限配置
     * @return
     */
    @PostMapping("/session")
    public ResponseMessage<User> session() {
        Account account=accountHandler.getPrincipal();
        User data = service.authorization(new User(account));
        return Result.success(data);
    }
    /**
     * 注册用户账户
     *
     * @param entity
     * @return
     */
    @PostMapping("/register")
    public ResponseMessage<User> register(@RequestBody Account entity) {
        service.register(entity);
        return Result.success();
    }
}
